package com.ky.serialport.sensor;

import com.ky.serialport.bean.ComBean;
import com.ky.serialport.utils.MyFunc;

/**
 * 电流传感器（柔性电流钳）
 */
public class RouXingDianLiuDataBean {

    public Long time = 0L;
    public int power = 0; //电量
    public int signal = 0; //信号
    public Float[] dianLiuArray = new Float[5]; //电流数据
    public float dainLiuVel = 0; //平均电流
    public int type = -1;
    public int index = -1;
    public ComBean comBean;

    public RouXingDianLiuDataBean() {
    }

    public RouXingDianLiuDataBean(ComBean comBean) {
        caculate(comBean.recData);
        time = comBean.recTime;
    }

    public RouXingDianLiuDataBean(byte[] recData) {
        caculate(recData);
    }

    public RouXingDianLiuDataBean caculate(ComBean comBean) {
        time = comBean.recTime;
        this.comBean = comBean;
        return caculate(comBean.recData);
    }

    public RouXingDianLiuDataBean caculate(byte[] buffer) {
        time = System.currentTimeMillis();
        signal = MyFunc.getSignal(buffer[26]); //测试信号
        power = MyFunc.getPower(buffer[24], buffer[25]);

        index = buffer[10];
        type = buffer[9];

        dianLiuArray[0] = (float) MyFunc.twoByte2IntNoSign(buffer[14], buffer[15])/100f;
        dianLiuArray[1] = (float) MyFunc.twoByte2IntNoSign(buffer[16], buffer[17])/100f;
        dianLiuArray[2] = (float) MyFunc.twoByte2IntNoSign(buffer[18], buffer[19])/100f;
        dianLiuArray[3] = (float) MyFunc.twoByte2IntNoSign(buffer[20], buffer[21])/100f;
        dianLiuArray[4] = (float) MyFunc.twoByte2IntNoSign(buffer[22], buffer[23])/100f;

        dainLiuVel = (dianLiuArray[0] + dianLiuArray[1] + dianLiuArray[2] + dianLiuArray[3] + dianLiuArray[4]) / 5f;
        return this;
    }
}
